package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.springdinner.SpringDinnerMgr;

import java.util.ArrayList;
import java.util.List;

public class SpringDinnerRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo != null) {
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            if (activityInfo.getChildType() == 1) {

                addMarkItem(activityInfo, SpringDinnerMgr.getRecoverItemId(), SpringDinnerMgr.getScoreItemId(), 1, recycleTime, 1);
            } else if (activityInfo.getChildType() == 2) {
                // 美团的直接回收
                addMarkItem(activityInfo, SpringDinnerMgr.getRecoverItemId(), SpringDinnerMgr.getScoreItemId(), 1, recycleTime, 2);
            }
        }
    }


    private void addMarkItem(ActivityInfo activityInfo, int itemId, int scoreItemId, int index, long recycleTime, int recycleType) {
        //标记道具
        List<String> paramList = new ArrayList<>();
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreItemId));
        paramList.add(String.valueOf(index));
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, recycleType, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SpringDinner.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        } else if (data.getRecycleType() == 2) {
            UserBagItem userBagItem = getUserBagItem(userId, data.getItemId());
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }

    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
